package command;

import java.io.IOException;

import org.springframework.web.multipart.MultipartFile;

import domain.Category;
import domain.Image;
import domain.Item;
import domain.Item.Type;


public class ItemForm {
	private String name;
	private double precio;
	private String description;
	private int count;
	private boolean newItem;
	private Category category;
	private boolean priority;
	private MultipartFile image;
	private Type type;
	
	public ItemForm(){
	}
	
	public ItemForm(Item item){
		this.name=item.getName();
		this.precio=item.getPrecio();
		this.description=item.getDescription();
		this.count=item.getCount();
		this.newItem=item.getNewItem();
		this.category=item.getCategory();
		this.priority=item.getPriority();
	}
	
	public void update(Item item){
		if (!this.image.isEmpty()){
			try {
				item.setImage(new Image(this.image.getBytes()));
			} catch (IOException e) {
				throw new RuntimeException("Error al leer el archivo de la imagen en el converter");
			}			
		}
		item.setName(name);
		item.setPrecio(precio);
		item.setDescription(description);
		item.setCount(count);
		item.setNewItem(newItem);
		item.setCategory(category);
		item.setPriority(priority);
	}
	
	
	public MultipartFile getImage() {
		return image;
	}
	public void setImage(MultipartFile image) {
		this.image = image;
	}	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public double getPrecio() {
		return precio;
	}
	public void setPrecio(double precio) {
		this.precio = precio;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public int getCount() {
		return count;
	}
	public void setCount(int count) {
		this.count = count;
	}
	public boolean getNewItem() {
		return newItem;
	}
	public void setNewItem(boolean newItem) {
		this.newItem = newItem;
	}
	public Category getCategory() {
		return category;
	}
	public void setCategory(Category category) {
		this.category = category;
	}
	public boolean getPriority() {
		return priority;
	}
	public void setPriority(boolean priority) {
		this.priority = priority;
	}
	
	public Type getType(){
		return this.type;
	}
	public void setType(Type type){
		this.type=type;
	}
}
